<template>
  <div id="app" v-loading="loading" class="app" :class="{darkApp:darkTheme}">
    <Header></Header>
    <router-view />
  </div>
</template>
<script>
import Header from '@/components/Header';
import {mapState} from 'vuex'
export default {
  components:{
    Header,
  },
  data(){
    return {
      loading:true
    }
  },
  computed:{
    ...mapState("common",["darkTheme"])
  },
  created () {
    // 在页面加载时读取sessionStorage
    if (sessionStorage.getItem('store')) {
      this.$store.replaceState(Object.assign({}, this.$store.state, JSON.parse(sessionStorage.getItem('store'))))
    }
    // 在页面刷新时将store保存到sessionStorage里
    window.addEventListener('beforeunload', () => {
      sessionStorage.setItem('store', JSON.stringify(this.$store.state))
    })
  },
  mounted(){
    this.$nextTick(()=>{
      this.loading = false
    })
  }
}
</script>

<style>
.app{
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  position: absolute;
  width: 100%;
  height: 100%;
}
.darkApp{
  background-color: #263c4f;
}

</style>
